package com.amit.jdbc.mysql;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class Lab4 {

	static Connection con=null;
	static PreparedStatement ps=null;
	
	public static void main(String[] args) throws Exception {
		
	
	if(args.length!=8)
	{
		System.out.println("enter id,name,email,phone,fee,date,month,year as CLA");
		System.exit(0);
		
	}
		try
		{
			int id=Integer.parseInt(args[0]);
			String name=args[1];
			String email=args[2];
			long phone=Long.parseLong(args[3]);
			float fee=Float.parseFloat(args[4]);
			int d=Integer.parseInt(args[5]);
			int m=Integer.parseInt(args[6]);
			int y=Integer.parseInt(args[7]);
			
		     Date dob=new Date(y-1900, m-1, d);
			
			//1.load the driver class
			Class.forName("com.mysql.jdbc.Driver");
			
			//2.ceate the connection
		 con=DriverManager.getConnection("jdbc:mysql://localhost:3306/amit007","root","root");
			
			//3.create the prepare statement
			
		 ps=con.prepareStatement("insert into jlcstudents values(?,?,?,?,?,?)");
			ps.setInt(1, id);
			ps.setString(2, name);
			ps.setString(3, email);
			ps.setLong(4, phone);
			ps.setFloat(5, fee);
			ps.setDate(6,dob);
			
			int i=ps.executeUpdate();
			System.out.println(i +"record inserted");
			
			
		}
		catch (Exception e) {
			con.close();
			
		
		}
		

	}

}
